﻿<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="SPTools.Ribbon"
    Location="CommandUI.Ribbon"
    RegistrationId="0x01"
    RegistrationType="ContentType" RequireSiteAdministrator="TRUE">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.List.Settings.Controls._children"  >            
              <Button
                Id="Ribbon.List.Settings.DeleteList"
                Command="DeleteListCommand"
                Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png" Image16by16Top="-112" Image16by16Left="-224"
                Image32by32="/_layouts/$Resources:core,Language;/images/formatmap32x32.png" Image32by32Top="-128" Image32by32Left="-128"
                 
              LabelText="Delete List"
              TemplateAlias="o2"
              Sequence="15" />
            </CommandUIDefinition>
        <CommandUIDefinition
          Location="Ribbon.Library.Settings.Controls._children">
          <Button
            Id="Ribbon.Library.Settings.DeleteList"
            Command="DeleteListCommand"
                Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png" Image16by16Top="-112" Image16by16Left="-224"
                Image32by32="/_layouts/$Resources:core,Language;/images/formatmap32x32.png" Image32by32Top="-128" Image32by32Left="-128"
            LabelText="Delete List"
            TemplateAlias="o2"
            Sequence="15" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>        
        <CommandUIHandler Command="DeleteListCommand" CommandAction="javascript:DeleteList()"  />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
    <CustomAction Id="Ribbon.Settings.Script"
                  Location="ScriptLink"
                  ScriptBlock ="
                  var listobj = null;
                  var listitle = null;
                  function DeleteList()
                  {
                  var listId = SP.ListOperation.Selection.getSelectedList();                          
                  var dlctx = new SP.ClientContext.get_current();                  
                  var dl_web = dlctx.get_web();                 
                  listobj = dl_web.get_lists().getById(listId);     
                  
                  listobj.deleteObject();                 
                  dlctx.executeQueryAsync(Function.createDelegate(this, this.DeleteListSucceeded), Function.createDelegate(this, this.DeleteListFailed));
                
                          }
                  function DeleteListSucceeded() {
                       alert('List Deleted');                         
                   
   
}

function DeleteListFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}        
                  
                  " >
  </CustomAction>

</Elements>
